import { defineStore } from "pinia";
import { Names } from "./store-name";
import { addAuthorized, deleteAuthorized, disabledAuthorized } from "@/api/authorized";
import { useRequest } from "alova";
import type { TAuthAddReq, TAuthDeletedReq, TAuthDisabledReq } from "@/typing/authorized";


export const useAuthorizedStore = defineStore(Names.AUTHORIZED, {
  state() {
    return {

    }
  },
  getters: {

  },
  actions: {
    addAuthorized(req: TAuthAddReq, fn: Function) {
      const { onSuccess } = useRequest(addAuthorized(req));
      onSuccess((res) => {
        fn && fn(res.data);
      });
    },
    disabledAuthorized(req: TAuthDisabledReq, fn: Function) {
      const { onSuccess } = useRequest(disabledAuthorized(req));
      onSuccess((res) => {
        if (res.data) {
          fn && fn(res.data);
        }
      });
    },
    deleteAuthorized(req: TAuthDeletedReq, fn: Function) {
      const { onSuccess } = useRequest(deleteAuthorized(req));
      onSuccess((res) => {
        if (res.data) {
          fn && fn(res.data);
        }
      });
    },
  }
})
